const {ccclass, property} = cc._decorator;

@ccclass
export default class GameControl4 extends cc.Component {
    public AwardNode: cc.Node;         //奖励父节
    private SelectNode: cc.Node;

    public rewardCount: number = 14;  
    private curIndex: number = 0;    //当前奖励下标
    private tagetIndex: number = 0;  //目标奖励下标
    private reawadArr: Array<Number> = [0, 1, 2, 3, 4, 5, 6, 7, 8 ,9, 10, 11, 12, 13];  //奖品名称


    private m_time: number = 0;
    private m_speed: number = 1;
    private m_curIndex: number = 0;

    onLoad () {
        this.AwardNode = cc.find("ZhuanPanRoot/RewardRoot", this.node);
        this.SelectNode = cc.find("ZhuanPanRoot/RewardRoot/SelectNode", this.node);
    }

    start () {
        //
    }

    private isTurnIng = false;
    public BtnCallBack() {
        if (this.isTurnIng) {
            return;
        }
        this.isTurnIng = true;

        let awardIndex = Math.floor(Math.random() * this.rewardCount);
        this.tagetIndex = awardIndex;

        console.log("========>>>>", awardIndex, this.reawadArr[awardIndex]);


    }


    protected update(dt: number): void {
        if (this.isTurnIng) {
            this.m_time++

            if (this.m_time > this.m_speed) {
                this.m_time = 0
                this.m_curIndex++
                if (this.m_curIndex > this.reawadArr.length - 1) {
                    this.m_curIndex = 0;
                    this.m_speed++;
                }
       
                if (this.m_speed == 3) {
                    this.m_speed = 8;
                }

                if (this.m_speed >= 9) {
                    if (this.m_curIndex == this.tagetIndex) {
                        this.isTurnIng = false;
                        this.m_speed = 0;
                        
                    }
                }

                this.SelectNode.active = true;
                this.SelectNode.setPosition(this.AwardNode.children[this.m_curIndex].position);
            }
        }
    }
}